package com.devilvan.betrice.douban.controller;

import com.devilvan.betrice.common.BetriceResultVo;
import com.devilvan.betrice.douban.po.DoubanCommentPo;
import com.devilvan.betrice.douban.po.DoubanMovieTop250Po;
import com.devilvan.betrice.douban.service.DoubanCommentService;
import com.devilvan.betrice.douban.service.DoubanMovieTop250Service;
import com.devilvan.betrice.util.UCollection;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author Evad.Wu
 * @Description 豆瓣-短评表 控制器
 * @date 2022-12-14
 */
@RestController
@RequestMapping(value = "doubanCommentController")
@Tag(name = "豆瓣-短评表 控制器")
public class DoubanCommentController {
    @Resource(name = "doubanCommentServiceImpl")
    private DoubanCommentService doubanCommentService;
    @Resource(name = "doubanMovieTop250ServiceImpl")
    private DoubanMovieTop250Service doubanMovieTop250Service;

    /**
     * 总请求控制器
     *
     * @return 形式返回
     */
    @Operation(summary = "总请求控制器")
    @GetMapping(value = "doDoubanComment")
    public BetriceResultVo<DoubanCommentPo> doDoubanComment() {
        BetriceResultVo<DoubanCommentPo> betriceResultVo = new BetriceResultVo<>();
        return betriceResultVo;
    }

    /**
     * 采集报文控制器
     *
     * @return 形式返回
     */
    @Operation(summary = "采集报文控制器")
    @GetMapping(value = "doDoubanCommentCrawler")
    public BetriceResultVo<DoubanCommentPo> doDoubanCommentCrawler() {
        BetriceResultVo<DoubanCommentPo> betriceResultVo = new BetriceResultVo<>();
        return betriceResultVo;
    }

    /**
     * 解析报文控制器
     *
     * @param doubanMovieTop250Po 查询到的电影记录
     * @param headers             请求头信息
     * @return 形式返回
     */
    @Operation(summary = "解析报文控制器")
    @GetMapping(value = "doDoubanCommentRequest")
    public BetriceResultVo<DoubanCommentPo> doDoubanCommentRequest(@RequestHeader Map<String, String> headers) {
        Map<String, String> subHeaders = UCollection.subMap(headers, "cookie", "host", "user-agent");
        DoubanMovieTop250Po doubanMovieTop250Po = doubanMovieTop250Service.findByPid(1291841L);
        return doubanCommentService.doDoubanCommentRequest(doubanMovieTop250Po, subHeaders);
    }
}
